import java.util.HashMap;

public class Solution {
    //方法一：暴力遍历
    //方法二：一次遍历
    public static int maxProfit(int[] prices) {
        int minprice=Integer.MAX_VALUE;
        int maxprofit=0;

        for(int i = 0 ; i < prices.length ; i++){
            if(prices[i] < minprice){
                minprice=prices[i];
            } else if(prices[i] - minprice > maxprofit){
                maxprofit = prices[i] - minprice;
            }
        }
       return maxprofit;
    }

    public static void main(String[] args) {
        int[] a ={7,6,4,3,1};
        int profit = maxProfit(a);
        System.out.println(profit);
    }
}
